package com.chixing.controller;

import com.chixing.service.FreeToWalkService;
import com.chixing.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping
public class FreeToWalkController {
    @Autowired
    private FreeToWalkService freeToWalkService;

    @GetMapping ("sights/page/{pageNum}")
    @ResponseBody
    public ServerResponse getSightsByMultiCondition(@PathVariable(value = "pageNum",required = false) Integer pageNum,
                                                    @RequestParam Float minPrice,
                                                    @RequestParam Float maxPrice,
                                                    @RequestParam Integer level,
                                                    @RequestParam String type
    ){
        if (pageNum ==null){
            pageNum = 1;
        }
        return freeToWalkService.getSightsByMultiCondition(minPrice,maxPrice,level,type,pageNum);
    }

    @GetMapping ("plans/page/{pageNum}")
    @ResponseBody
    public ServerResponse getPlanByMultiCondition(@PathVariable(value = "pageNum",required = false) Integer pageNum,
                                                    @RequestParam Float minPrice,
                                                    @RequestParam Float maxPrice,
                                                    @RequestParam Integer perNum,
                                                    @RequestParam Integer days
    ){
        if (pageNum ==null){
            pageNum = 1;
        }
        return freeToWalkService.getPlanByMultiCondition(minPrice,maxPrice,perNum,days,pageNum);
    }
    @GetMapping("sights/details/{id}")
    public ModelAndView getSightsById(@PathVariable("id")Integer id){
        ServerResponse response = freeToWalkService.getSightById(id);
        ModelAndView mav = new ModelAndView();
        mav.addObject("response",response);
        mav.setViewName("travel/scenic_detail");
        return mav;
    }
}
